﻿using DevExpress.XtraEditors;
using DevTeam;


using System;
using System.Data;
using System.Drawing;

namespace ConfExpert.Forms.Planlama
{
    public partial class GomlekDepo : XPopupForm
    {
        DataTable dt;
        int DepoId;
        public GomlekDepo(DataTable dt,int DepoId)
        {
            InitializeComponent();
            this.dt = dt;
            this.DepoId = DepoId;
        }

        private void GomlekDepo_Load(object sender, EventArgs e)
        {
            //dt.Columns.Add("GirilecekAdet", typeof(int),"Kesilen");
            gridView1.Init(dt);
            gridView1.MakeReadOnly("GirilebilirAdet");
            gridView1.MakeColumnInvisible("AtelyeId","Seç","KesilenAdet","Yuklenen","Kalan1Kalite","Kalite2","Kalite3","Numune","EksikAdet","Iptal");
            btnTransfer.ItemClick += btnTransfer_ItemClick;
            gridView1.RowCellStyle += gridView1_RowCellStyle;
            gridView1.MakeEditable("Kesilen");
        }

        void gridView1_RowCellStyle(object sender, DevExpress.XtraGrid.Views.Grid.RowCellStyleEventArgs e)
        {
            if (e.Column.FieldName == "GirilebilirAdet")
            {
                e.Appearance.Font = new Font(DevExpress.Utils.AppearanceObject.DefaultFont, FontStyle.Bold);
            }
        }

        void btnTransfer_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            
            gridView1.EndEditing();
            for (int i = 0; i < gridView1.DataRowCount; i++)
            {
                if(gridView1.GetRowCellValue(i, "GirilebilirAdet").ToInt()>(0-gridView1.GetRowCellValue(i, "Fark").ToInt()))
                {
                    XtraMessageBox.Show("Depoya transfer edilecek gömlek sayısı,transfer edilebilecek gömlek sayısından fazla olamaz!");
                    return;
                }
            }
            string xml = dt.Serialize();
          //  gridView1.VeriyiGuncelle("GetModel");
            ExecuteNonQuery("InsGomlekStok", dt.Serialize(),DepoId,WhoAmI);
            this.Close();
            //gridView1.VeriyiGuncelle("GetModel");
        }
    }
}
